FROM ubuntu:22.04 as builder
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    g++ \
    make \
    && rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY ./main.cpp .
RUN g++ -Wall -Wextra -O2 -o mycppweb main.cpp -lpthread

FROM ubuntu:22.04
COPY --from=builder /src/mycppweb /usr/local/bin/
RUN groupadd -r appgroup && \
    useradd -r -g appgroup appuser && \
    chown appuser:appgroup /usr/local/bin/mycppweb && \
    chmod 755 /usr/local/bin/mycppweb
USER appuser
EXPOSE 8081
CMD ["/usr/local/bin/mycppweb"]
